<?php
class SystemparamController extends Controller {
	public function index() {
		$this->getSmarty ();
		// $this->smarty->assign ( 'page_no', $page_no );
		// $this->smarty->assign ( 'page_html', $page_html );
		$this->smarty->display ( "admin/systemparam.tpl" );
	}
	 
	
	public function addOrModify() {
		$this->getSmarty ();
		require_once SERVICE . DS . 'admin' . DS . 'SystemparamService.class.php';
		if (! CommonBase::isPost ()) {
			$this->smarty->display ( "admin/systemparam.tpl" );
			return;
		}
		$paramService = new SystemparamService ( $this->getDB () );
		$id = $_POST ["id"];
		if (empty ( $id )) {
			$input_data = array (
					'name' => $_POST ["name"],
					'value' => $_POST ["value"],
					'uiFlag' => $_POST ["uiFlag"],
					'paramdesc' => $_POST ["paramdesc"]
			);
			$user_id = $paramService->add ( $input_data );
		} else {
			
			$input_data = array (
					'name' => $_POST ["name"],
					'value' => $_POST ["value"],
					'uiFlag' => $_POST ["uiFlag"],
					'paramdesc' => $_POST ["paramdesc"]
			);
			$input_condition = array (
					'id' => $_POST ["id"] 
			);
			
			$user_id = $paramService->edit ( $input_data, $input_condition );
		}
		echo "1";
	}
 
	public function delete() {
		$this->getSmarty ();
		require_once SERVICE . DS . 'admin' . DS . 'SystemparamService.class.php';
		$paramService = new SystemparamService ( $this->getDB () );
		$id = $_POST ['id'];
		$user_id = $paramService->delete ( $id );
		echo 1;
	}
	function getpage() {
		$this->getSmarty ();
		require_once SERVICE . DS . 'admin' . DS . 'SystemparamService.class.php';
		// START 数据库查询及分页数据
		$paramService = new SystemparamService ( $this->getDB () );
		
		$page = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rows = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$offset = ($page - 1) * $rows;
		$result = array ();
		$row_count = $paramService->countNum ();
		$result ["total"] = $row_count;
		$user_infos = $paramService->userPage ( $offset, $rows );
		$items = array ();
		// while($row = $user_infos->fetch_assoc()){
		// print ($row);
		// array_push($items, $row);
		// }
		$result ["rows"] = $user_infos;
		echo json_encode ( $result );
		// $this->smarty->display("admin/user_list.tpl");
	}
	 
}